<?php
namespace App\Http\Models;
use Illuminate\Support\Facades\Session;
use Illuminate\Database\Eloquent\Model;

class UserOrder extends Model{

    protected $table = 'tcustomerorder';

    public $timestamps=true;

    protected $fillable = ['COCustomerID','COPayed','COCost'];

    //创建订单
    public static function createOrder($input=array())
    {
        $input['COCustomerID'] = Session::get(User::$session_key);

        $input['COPayed']='cancel';

        return self::create($input);

    }

    public function doSave($input = array())
    {
        $id = array_pull($input, 'COID');

        if ($id) {
            //$input=array_only($input,array('CSex','CName'));
            return self::where('COID',$id)->update($input);
        } else {
            $user=self::create($input);
            return $user;
        }
    }
}